package com.iwuke.dance.career.fragment;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.iwuke.dance.R;
import com.iwuke.dance.activity.BaseFragment;
import com.iwuke.dance.career.fragment.adapter.AllActivityAndEventAdapter;
import com.scwang.smart.refresh.footer.ClassicsFooter;
import com.scwang.smart.refresh.header.ClassicsHeader;
import com.scwang.smart.refresh.layout.api.RefreshLayout;
import com.scwang.smart.refresh.layout.listener.OnLoadMoreListener;
import com.scwang.smart.refresh.layout.listener.OnRefreshListener;

import java.util.ArrayList;
import java.util.List;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.recyclerview.widget.RecyclerView;

/**
 * @author: 魏从响
 * @date: 2025/10/16
 */
public class EventFragment extends BaseFragment {

    private View view;

    public View onCreateView(@NonNull LayoutInflater inflater,
                             ViewGroup container, Bundle savedInstanceState) {
        if (view==null) {
            view = inflater.inflate(R.layout.fragment_all_activity_and_event, container, false);
        }else {
            // 如果view不为空，说明是恢复状态，需要将视图从之前的父布局中移除
            ViewGroup parent = (ViewGroup) view.getParent();
            if (parent != null) {
                parent.removeView(view);
            }
        }
        return view;
    }

    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        // 将原来 onActivityCreated 中的大部分代码移到这里
        RefreshLayout refreshLayout = view.findViewById(R.id.refresh_layout);
        RecyclerView recycler_view = view.findViewById(R.id.recycler_view);
        //初始化逻辑
        List<String> lists = new ArrayList<>();
        lists.add("1");
        lists.add("1");
        if (radioButton!=null) {
            radioButton.setText(getString(R.string.event_name)+"\n(" + lists.size() + ")");
        }
        setLinearLayoutManager(getActivity(), recycler_view);
        AllActivityAndEventAdapter adapter = new AllActivityAndEventAdapter(getActivity(), R.layout.adapter_all_activity_and_event, lists);
        recycler_view.setAdapter(adapter);

        refreshLayout.setRefreshHeader(new ClassicsHeader(getActivity()));
        refreshLayout.setRefreshFooter(new ClassicsFooter(getActivity()));
        refreshLayout.setOnRefreshListener(new OnRefreshListener() {
            @Override
            public void onRefresh(RefreshLayout refreshlayout) {
                refreshlayout.finishRefresh(2000/*,false*/);//传入false表示刷新失败
//                pageNum=1;
//                requestBalance();
            }
        });
        refreshLayout.setOnLoadMoreListener(new OnLoadMoreListener() {
            @Override
            public void onLoadMore(RefreshLayout refreshlayout) {
                refreshlayout.finishLoadMore(2000/*,false*/);//传入false表示加载失败
//                pageNum++;
//                requestBalance();
            }
        });

    }

    @Override
    protected void lazyLoad() {

    }
}
